package org.crazyit.activiti_d1._9_DuplicateFilter;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.DeploymentBuilder;

public class DuplicateFilter {

    public static void main(String[] args) {

        //1. 创建流程引擎
        ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();

        //2. 得到流程存储服务实例
        RepositoryService repositoryService = engine.getRepositoryService();

        //3. 创建第一个部署对象
        DeploymentBuilder builderA = repositoryService.createDeployment();
        builderA.addClasspathResource("DuplicateFilter.txt");
        builderA.name("DuplicateFilterA");
        builderA.deploy();

        //4. 由于资源一样, 并且调用了enableDuplicateFiltering() 方法, 因此不会再写入数据库中
        DeploymentBuilder builderB = repositoryService.createDeployment();
        builderB.addClasspathResource("DuplicateFilter.txt");
        builderB.name("DuplicateFilterA");
        builderB.enableDuplicateFiltering();
        builderB.deploy();

        //5. 由于资源发生变化, 即使调用了enableDuplicateFiltering() 方法, 也会写到数据库中
        DeploymentBuilder builderC = repositoryService.createDeployment();
        builderC.addClasspathResource("DuplicateFilterB.txt");
        builderC.name("DuplicateFilterA");
        builderC.enableDuplicateFiltering();
        builderC.deploy();

        //6. 得到第二个流程存储服务实例
        RepositoryService repositoryService1 = engine.getRepositoryService();

        //7. 即使资源一样, 并且也调用了enableDuplicateFiltering() 方法, 但是由于使用不同的流程存储服务, 导致资源管理也不同, 同样可以部署成功
        DeploymentBuilder builderD = repositoryService1.createDeployment();
        builderD.addClasspathResource("DuplicateFilter.txt");
        builderD.name("DuplicateFilterA");
        builderD.deploy();

    }

}
